﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.ServiceModel.Description;
using Skynet.CommonLibrary.WCF;

namespace ServiceHosting
{
    class Program
    {
        static void Main(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
            try
            {
                ServiceHost _dbHost = new ServiceHost(typeof(DataAccessCenter));
                _dbHost.Open();
                WriteAddress(_dbHost);

            }
            catch (Exception ex)
            {
                Console.WriteLine("DataAccessCenter 绑定错误");
                Console.WriteLine(ex.Message);
            }

            Console.Read();
        }

        static void WriteAddress(ServiceHost host)
        {
            foreach (ServiceEndpoint endpoint in host.Description.Endpoints)
            {
                Console.WriteLine(host.Description.Name);
                Console.WriteLine("\tAddress: {0}\n\tBinding: {1}\n\tContract: {2}", endpoint.Address, endpoint.Binding, endpoint.Contract.Name);
            }
        }

        static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            Console.WriteLine(e.ExceptionObject);
        }
    }
}
